<?php


namespace app\callback;
use app\api\controller\Base;
use app\model\CompanyBalance;
use app\model\LeasingCompany;
use app\model\Member;
use app\model\Member as SelfModel;
use app\model\MemberBrokerage;
use app\model\MemberIntegral;
use app\model\MemberInvite;
use app\model\MemberRecharge;
use app\model\Order;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Db;

class Pay
{
    /**
     * 在回调里处理好要给的参数
     * 这里就是只处理业务逻辑 不在判断是微信还是支付宝
     * 加了回滚
     */
    public function business_logic($data)
    {

        paylog('Pay/logic','wechat');
        paylog($data);
        Db::name('unifiedorder')->where('order_number', $data['out_trade_no'])->where('status', 1)->update(['status' => 2]);
        $unifiedorder = Db::name('unifiedorder')->where('order_number', $data['out_trade_no'])->find();

        $member_id = $unifiedorder['member_id'];
        $price = $unifiedorder['price'];
        $order_number = $unifiedorder['order_number'];
        $send_score = $unifiedorder['send_score'];
        Db::startTrans();
        try {
//            if($pay_type == 'wechat'){ $attach = $data['attach']; $payment = '微信'; }
//            if($pay_type == 'alipay'){ $attach = $data['attach']; $payment = '支付宝'; }

            if ($data['pay_action'] == '订单') {
               Order::order_update($data['out_trade_no']);
//               Order::where('order_number',$data['out_trade_no'])->update(['pay_type'=>'3']);//1微信 2支付宝 3积分
            }


            Db::commit();
        }catch (\Exception $e) {
            Db::rollback();

            paylog('#####'.$e->getMessage().'#####','alipay');
        }
        return true; //ret肯定是true 数据里返回不返回true不重要
    }
}